package com.consumer.config;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description
 * @Author youxin
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2021/11/18
 */
//@Configuration
public class OrderConsumerConfiguration {
    @Value("${rocketmq.cancel.order.topic}")
    private String cancelTopic;
    @Value("${rocketmq.order.group.topic}")
    private String orderGroupTopic;
    @Value("${rocketmq.namesrv.address}")
    private String namesrvAddr;


    @Bean
    public DefaultMQPushConsumer cancelOrderConsumer(@Qualifier(value = "orderMessageListenner") OrderMessageListenner orderMessageListenner) throws MQClientException {
        DefaultMQPushConsumer defaultMQPushConsumer = new DefaultMQPushConsumer(orderGroupTopic);
            defaultMQPushConsumer.subscribe(cancelTopic, "*");
            defaultMQPushConsumer.setNamesrvAddr(namesrvAddr);
            defaultMQPushConsumer.start();
            return defaultMQPushConsumer;
    }
}
